/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bionic.socialNet.command;

import static com.bionic.socialNet.manager.AttributeNames.*;
import com.bionic.socialNet.manager.Config;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author Ann Class is called when redirect to some page has to be executed:
 * this class gets redirect page string from request
 */
public class CommandGotoPage implements ICommand {

    @Override
    public String execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // an attribute 'REDIRECT_PAGE_CONFIG_NAME' contains name of property in Config file, which contains page address
        String ConfigPageName = (String) request.getParameter(REDIRECT_PAGE_CONFIG_NAME); 
        String page = null;
        if (ConfigPageName != null) {
            page = Config.getInstance().getProperty(ConfigPageName);
        }
        if (page == null) {
            request.setAttribute(ERROR_MESSAGE, "Redirect to null page.");
            page = Config.getInstance().getProperty(Config.ERROR);
        }
        return page;

    }
}
